<?php
/**
 * Created by PhpStorm.
 * User: meng
 * Date: 2021/7/26
 * Time: 1:22 下午
 */

namespace app\admin\controller;


use app\admin\model\FileModel;
use app\utils\FileUtils;

class File extends AdminBaseController
{
    public function upload () {
        $files = $this->request->file();
        $fileUtils = new FileUtils(array_values($files)[0]);
        $data = $fileUtils->upload(true);
        $this->writeJson($data);
    }

    // 检测文件是否存在
    public function chunkPresence () {
        $params = $this->request->param();
        $data = FileModel::checkPresence($params);
        $this->writeJson($data);
    }

    // 合并分片
    public function chunkMerge () {
        $params = $this->request->param();
        $data = FileModel::mergeChunks($params);
        $this->writeJson($data);
    }

    // 上传分片
    public function chunk () {
        $files = $this->request->file();
        FileModel::uploadChunk(array_values($files));
        $this->writeJson();
    }
}
